import { mapGetters, mapActions } from 'vuex'
import { getDeviceIds } from 'src/boot/maintenance/maintenance-plan'
export default {
  name: 'maintenance-mixin',
  data () {
    return {
      fuzzyFunc: getDeviceIds,
      fuzzyParams: {
        schemeId: '',
        schemeLevel: 2,
        pageNum: 1,
        pageSize: 1000,
        deviceType: null
      },
      pagination: {
        pageNum: 1, // 当前页码
        pageSize: 15, // 每页条数
        rowsNumber: 0 // 总条数
      },
      // 时间排序
      isSortTime: true
    }
  },
  computed: {
    ...mapGetters({
      'workshopslist': 'maintenance/workshopslist',
      'deviceTypesList': 'maintenance/deviceTypesList',
      'maintainItemContent': 'maintenance/maintainItemContent'
    })
  },
  methods: {
    onSubmit () {
      this.pagination.pageNum = 1
      this.getList()
    },
    onSelectWorkShop (val) {
      this.fuzzyParams.schemeId = val === 'all' ? '' : val
      this.queryParams.deviceCode = ''
    },
    onSelectDeviceType (val) {
      this.fuzzyParams.deviceType = val === 'all' ? null : val
    },
    ...mapActions({
      'getWorkshopsList': 'maintenance/getWorkshopsList',
      'getDeviceTypesList': 'maintenance/getDeviceTypesList',
      'getMaintainItemContent': 'maintenance/getMaintainItemContent'
    }),
    resetSearch () {
      Object.assign(this.queryParams, this.$options.data.call(this).queryParams)
    },
    onSeletByTime () {
      this.isSortTime = !this.isSortTime
      this.queryParams.sort = this.isSortTime ? 0 : 1
      this.getList()
    }
  },
  mounted () {
    this.getDeviceTypesList(true)
    this.getWorkshopsList()
    this.getMaintainItemContent(true)
  }
}
